import java.util.Scanner;
public class Main {

    static void YangHuiTriangle(int n){
        CSeqQueue<Integer> q = new CSeqQueue<Integer>();
        int s = 0,t = 0;
        q.push(1);
        q.push(1);
        if(n!=0)
        System.out.println("1");
        for(int i = 1;i<n;i++){
            q.push(0);
            for(int j = 1; j <= i+2; j++){
                t = q.pop();
                q.push(s+t);
                s = t;
                if(j!=i+2)
                System.out.printf("%-4d",s);
            }
            System.out.println();
        }
    }

    static void Joseph(){
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入n(人数):");
        int n = sc.nextInt();
        System.out.println("请输入m(密钥):");
        int m = sc.nextInt();
        int arr[] = new int[n];
        int pos = 0;

        LinkQueue<Integer> q = new LinkQueue<Integer>();
        for(int i =1;i<=n;i++){
            q.push(i);
        }
        while(!q.empty()){
            for(int j =1;j<m;j++){
                int k = q.pop();
                q.push(k);
            }
            int k = q.pop();
            arr[pos++] = k;
        }
        for(int i = 0;i<n;i++){
            System.out.print(arr[i]+" ");
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.println("------杨辉三角------请输入行数：");
        int n = sc.nextInt();
        YangHuiTriangle(n);

        System.out.println("------约瑟夫环------");
        Joseph();
    }
}